package com.neulogistics.contrib.warehouse.infrastructure.persistence.repository;

import com.neulogistics.contrib.warehouse.domain.model.aggregate.CirculationOrder;
import com.neulogistics.contrib.warehouse.domain.repository.ICirculationOrderRepository;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.converter.CirculationOrderEntityPOConverter;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.orm.po.CirculationOrderPO;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.orm.service.ICirculationOrderPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class CirculationOrderRepository implements ICirculationOrderRepository {
    @Resource
    ICirculationOrderPOService circulationOrderPOService;

    @Override
    public void save(CirculationOrder circulationOrder) {
        CirculationOrderPO circulationOrderPO =
                CirculationOrderEntityPOConverter.entityToPO(circulationOrder);
        circulationOrderPOService.saveOrUpdate(circulationOrderPO);
    }

    @Override
    public CirculationOrder findById(Long id) {
        CirculationOrderPO circulationOrderPO = circulationOrderPOService.getById(id);
        CirculationOrder circulationOrder = CirculationOrderEntityPOConverter.POToEntity(circulationOrderPO);
        return circulationOrder;
    }

    @Override
    public void deleteById(Long id) {
        circulationOrderPOService.removeById(id);
    }
}
